package com.wude.tools;

import android.annotation.SuppressLint;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtil {

	/** 格式化时间戳 */
	@SuppressLint("SimpleDateFormat")
	public static String formatTime(String timeStamp) {
		final String format1 = "yy-MM-dd HH:mm:ss";
		@SuppressWarnings("unused")
		final String format2 = "yyyy-MM-dd HH:mm:ss";
		if (null == timeStamp || "".equals(timeStamp)) {
			return "";
		}
		/** 10位数时间戳 */
		if (timeStamp.length() == 10) {
			timeStamp += "000";
		}
		DateFormat df = new SimpleDateFormat(format1);
		long ltime = Long.parseLong(timeStamp);
		return df.format(ltime);
	}

	/**
	 * 将时间戳转换为字符串 yyyy-MM-dd
	 * @param
	 * @param
	 * @return
	 */
	public static String GetTime(String time) {
		SimpleDateFormat sdr = new SimpleDateFormat("yyyy-MM-dd");
		@SuppressWarnings("unused")
		long lcc = Long.valueOf(time);
		int i = Integer.parseInt(time);
		String times = sdr.format(new Date(i * 1000L));
		return times;
	}

    /**
     * 转化时间输入时间与当前时间的间隔
     *
     * @param timestamp
     * @return
     */
    public static String converTime(long timestamp) {
        long currentSeconds = System.currentTimeMillis() / 1000;
        long timeGap =timestamp - currentSeconds;// 输入时间与现在时间相差秒数
        String timeStr = null;
        if (timeGap > 24 * 60 * 60) {// 1天以上
            timeStr = timeGap / (24 * 60 * 60) + "天";
        } else if (timeGap > 60 * 60) {// 1小时-24小时
            timeStr = timeGap / (60 * 60) + "小时";
        } else if (timeGap > 60) {// 1分钟-59分钟
            timeStr = timeGap / 60 + "分钟";
        }
        return timeStr;
    }

}
